jQuery(document).ready(function()
{
    var url = location.href;
    var reg = /app_dev\.php/gi;
    var reg2 = /app\.php/gi;
    var result = url.match(reg);
    if (!result)
        result = url.match(reg2);
    
    url = url.split(/\//);
    var dir = '';
    if (result)
        var length = url.length-2;
    else
        var length = url.length-1;
    for(var i=0; i<length; i++) 
    {
        dir += url[i] + "/";
    }
    dir += "bundles/billing";

    load_logo = '<img alt="загрузка" src="' + dir + '/i/load.gif">';
    error_logo = '<img alt="загрузка" src="' + dir + '/i/error.jpeg">';

    var timeout = 10000;
    function refreshData()
    {
       $.ajax(
       {
          url:'./shared_info/update',
          cache: false,
          success: function(html)
          {
             eval(html);
             setTimeout(function(){refreshData()},timeout);
          }
       });
    }
    refreshData();
    function sort_items(order, domain)
    {
        var emails = $('#email_list[order="' + order + '"][domain="' + domain + '"] #email_item');
        var emails_heads = $('#email_list[order="' + order + '"][domain="' + domain + '"] div span');
        $('#email_list[order="' + order + '"][domain="' + domain + '"]').empty();
        var heads = [];
        var temp_heads = [];
        $.each(emails_heads, function(index, obj)
        {
            heads[index] = $(obj).html();
            temp_heads[$(obj).html()] = index;
        }
        );
        heads.sort();
        var blocks = [];
        $.each(emails, function(index, obj)
        {
            blocks[index] = $(obj);
        }
        );
        //alert(heads);
        for (var i=0; i < heads.length; i++) 
        {
            blocks[temp_heads[heads[i]]].appendTo($('#email_list[order="' + order + '"][domain="' + domain + '"]'));
            restore_email_validation(order, heads[i]);
        }
    }
    function sort_databases(order)
    {
        var databases = $('#database_list[order="' + order + '"] #base_item');
        var databases_heads = $('#database_list[order="' + order + '"] div h2 span');
        $('#database_list[order="' + order + '"]').empty();
        var heads = [];
        var temp_heads = [];
        $.each(databases_heads, function(index, obj)
        {
            heads[index] = $(obj).html();
            temp_heads[$(obj).html()] = index;
        }
        );
        heads.sort();
        var blocks = [];
        $.each(databases, function(index, obj)
        {
            blocks[index] = $(obj);
        }
        );
        for (var i=0; i < heads.length; i++) 
        {
            blocks[temp_heads[heads[i]]].appendTo($('#database_list[order="' + order + '"]'));
            sort_mysql_users(heads[i], order);
            restore_create_mysql_user_validation(order, heads[i]);
        }       
    }
    function sort_mysql_users(base, order)
    {
        var users = $('#users_list[order="' + order + '"][base="' + base + '"] #user_item');
        var users_heads = $('#users_list[order="' + order + '"][base="' + base + '"] div span');
        $('#users_list[order="' + order + '"][base="' + base + '"]').empty();
        var heads = [];
        var temp_heads = [];
        $.each(users_heads, function(index, obj)
        {
            heads[index] = $(obj).html();
            temp_heads[$(obj).html()] = index;
        }
        );
        //alert(heads);
        heads.sort();
        var blocks = [];
        $.each(users, function(index, obj)
        {
            blocks[index] = $(obj);
        }
        );
        for (var i=0; i < heads.length; i++) 
        {
            blocks[temp_heads[heads[i]]].appendTo($('#users_list[order="' + order + '"][base="' + base + '"]'));
            restore_change_mysql_user_validation(order, base, heads[i]);
        }
    }
    function sort_ftp_users(order)
    {
        var users = $('#ftp_list[order="' + order + '"] table tbody tr');
        var users_heads = $('#ftp_list[order="' + order + '"] table tbody td span');
        $('#ftp_list[order="' + order + '"] table tbody').empty();
        var heads = [];
        var temp_heads = [];
        $.each(users_heads, function(index, obj)
        {
            heads[index] = $(obj).html();
            temp_heads[$(obj).html()] = index;
        }
        );
        //alert(heads);
        heads.sort();
        var blocks = [];
        $.each(users, function(index, obj)
        {
            blocks[index] = $(obj);
        }
        );
        for (var i=0; i < heads.length; i++) 
        {
            blocks[temp_heads[heads[i]]].appendTo($('#ftp_list[order="' + order + '"] table tbody'));
            var temp = heads[i].split("@");
            restore_change_ftp_validation(order, temp['0']);
        }
    }
    function sort_dns(order)
    {
        var dnss = $('#dns_list[order="' + order + '"] #dns_item');
        //var dns_heads = $('#dns_list[order="' + order + '"] div span');
        $('#dns_list[order="' + order + '"]').empty();
        var heads = [];
        var temp_heads = [];
        $.each(dnss, function(index, obj)
        {
            heads[index] = $(obj).attr("name")+$(obj).attr("hashs");
            temp_heads[$(obj).attr("name")+$(obj).attr("hashs")] = index;
        }
        );
        heads.sort();
        var blocks = [];
        $.each(dnss, function(index, obj)
        {
            blocks[index] = $(obj);
        }
        );
        for (var i in heads) 
        {
            blocks[temp_heads[heads[i]]].appendTo($('#dns_list[order="' + order + '"]'));
            //restore_dns_validation(order, heads[i]);
        }
    }
    
    $('#order_shared_choice').live('click', function()
    {
        $('li:has(a#order_shared_choice)').removeClass("active");
        var order = $(this).attr("order"); 
        $('li:has(a#order_shared_choice[order="' + order + '"])').addClass("active");
        var url = '#shared:';
        url += order + '=summary';
        location.href = 'panel' + url;
        $.ajax(
        {
             type: 'POST',
             data: {order:order},
             url: "./shared_summary/show",
             cache: false,
             beforeSend: function()
             {
                $('#shared_content').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
             },
             success: function(html)
             {
                $('#shared_content').html(html);
             }
        });
        return false;
    });
    $('#summary').live('click', function()
    {
        //if (!$(this).hasClass('current'))
        //    return false;
        var order = $(this).attr("order");  
        
        $.ajax(
        {
             type: 'POST',
             data: {order:order},
             url: "./shared_summary/show",
             cache: false,
             beforeSend: function()
             {
                $('#content[order="' + order + '"]').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
             },
             success: function(html)
             {
                $('#content[order="' + order +'"]').html(html);
             }
        });
        return false;
    });
    $('#domains').live('click', function()
    {
        //if (!$(this).hasClass('current'))
        //    return false;
        var order = $(this).attr("order");
        if ($('#domains a i').hasClass("icon-chevron-down"))
        {
            $('#domains a i').removeAttr("class");
            $('#domains a i').addClass("icon-chevron-up");
            $('#domains_content').html('');
            return false;
        }
        $('#domains a i').removeAttr("class");
        $('#domains a i').addClass("icon-chevron-down");
        $.ajax(
        {
             type: 'POST',
             data: {order:order},
             url: "./shared_domains/show",
             cache: false,
             beforeSend: function()
             {
                $('#domains_content').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
                //$('#content[order="' + order + '"]').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
             },
             success: function(html)
             {
                $('#domains_content').html(html);
                //$('#content[order="' + order +'"]').html(html);
             }
        });
        return false;
    });
    $('a#dns').live('click', function()
    {
        var order = $(this).attr("order");
        var domain = $(this).attr("domain");
        $.ajax(
        {
             type: 'POST',
             data: {order:order, domain:domain},
             url: "./shared_dns/show",
             cache: false,
             beforeSend: function()
             {
                $('#content[order="' + order + '"]').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
             },
             success: function(html)
             {
                restoreSharedLinks(order);
                $('#content[order="' + order +'"]').html(html);
                sort_dns(order);
             }
        });
        return false;
    });
    $('#databases').live('click', function()
    {
        //if (!$(this).hasClass('current'))
        //    return false;
        var order = $(this).attr("order");
        if ($('#databases a i').hasClass("icon-chevron-down"))
        {
            $('#databases a i').removeAttr("class");
            $('#databases a i').addClass("icon-chevron-up");
            $('#databases_content').html('');
            return false;
        }
        $('#databases a i').removeAttr("class");
        $('#databases a i').addClass("icon-chevron-down");
        $.ajax(
        {
             type: 'POST',
             data: {order:order},
             url: "./shared_databases/show",
             cache: false,
             beforeSend: function()
             {
                $('#databases_content').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
             },
             success: function(html)
             {
                /*if ( $('#load_icon_synch_db[order="' + order + '"]').is(':hidden') )
                    show_load = "0";
                else
                    show_load = "1";*/
                $('#databases_content').html(html);
                sort_databases(order);
                //if (show_load == "1")
                //    $('#load_icon_synch_db[order="' + order + '"]').show();
             }
        });
        return false;
    });
    $('#ftp').live('click', function()
    {
        var order = $(this).attr("order");
        if ($('#ftp a i').hasClass("icon-chevron-down"))
        {
            $('#ftp a i').removeAttr("class");
            $('#ftp a i').addClass("icon-chevron-up");
            $('#ftp_content').html('');
            return false;
        }
        $('#ftp a i').removeAttr("class");
        $('#ftp a i').addClass("icon-chevron-down");
        $.ajax(
        {
             type: 'POST',
             data: {order:order},
             url: "./shared_ftp/show",
             cache: false,
             beforeSend: function()
             {
                $('#ftp_content').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
             },
             success: function(html)
             {
                $('#ftp_content').html(html);
                sort_ftp_users(order);
             }
        });
        return false;
    });
    $('#email').live('click', function()
    {
        //if (!$(this).hasClass('current'))
        //    return false;
        var order = $(this).attr("order");
        if ($('#email a i').hasClass("icon-chevron-down"))
        {
            $('#email a i').removeAttr("class");
            $('#email a i').addClass("icon-chevron-up");
            $('#email_content').html('');
            return false;
        }
        $('#email a i').removeAttr("class");
        $('#email a i').addClass("icon-chevron-down");
        $.ajax(
        {
             type: 'POST',
             data: {order:order},
             url: "./shared_email/show",
             cache: false,
             beforeSend: function()
             {
                $('#email_content').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
             },
             success: function(html)
             {
                $('#email_content').html(html);
                var domains = $('#domain_list[order="' + order + '"] h2 span');
                $.each(domains, function(index, obj)
                {
                    sort_items(order, $(obj).html());
                }
                );
             }
        });
        return false;
    });

    $('div[name="human_link"]').live('click', function()
    {
        var order = $(this).attr("order");
        var action = $(this).attr("action");    
        var object = $('#' + action + '[order="' + order + '"]:first');
        var text = $('#' + action + '[order="' + order + '"] a').html();

        $('.current[order="' + order +'"]').removeClass('current');
        $(object).addClass('current');
        var url = '#shared:';
        $.each($('.current'), function(index,value)
        {
           url = url + $(value).attr("order") + "=" + $(value).attr("id");                    
           if (($('.current').size() > 1) && (index != $('.current').size() - 1))
               url += ",";
        });
        location.href = 'panel' + url;

        $('div[name="default"][link="shared_tab"]').html('<a href="' + url + '" class="tab">Заказы</a>');
        //alert(text);
        if (text)
        {
            if ((text != "Управление ip") && (text != "Добавить домен к заказу"))
            {
                restoreSharedLinks(order);
                $('#' + action + '[order="' + order + '"]').html('<b>'+ text +'</b>');
            }
        }
    });

    $('a#add_database_link').live('click', function()
    {
        var order = $(this).attr("order");
        $('#add_database_content[order="' + order + '"]').hide(1000);
        if ( $('#add_database_content[order="' + order + '"]').is(':hidden') )
            $('#add_database_content[order="' + order + '"]').show(1000);
        return false;
    });
    $('a#add_mysql_user_link').live('click', function()
    {
        var order = $(this).attr("order");
        var base = $(this).attr("base");
        $('#add_mysql_user_content[order="' + order + '"][base="' + base + '"]').hide(1000);
        if ( $('#add_mysql_user_content[order="' + order + '"][base="' + base + '"]').is(':hidden') )
            $('#add_mysql_user_content[order="' + order + '"][base="' + base + '"]').show(1000);
        return false;
    });
    $('a#privileges_link').live('click', function()
    {
        var order = $(this).attr("order");
        var user = $(this).attr("user");
        var base = $(this).attr("base");
        $('#change_mysql_password_content[order="' + order + '"][base="' + base + '"]').hide(1000);
        $('#privileges_content[order="' + order + '"][base="' + base + '"]').hide(1000);
        if ( $('#privileges_content[order="' + order + '"][user="' + user + '"][base="' + base + '"]').is(':hidden') )
            $('#privileges_content[order="' + order + '"][user="' + user + '"][base="' + base + '"]').show(1000);
        return false;
    });
    $('a#change_mysql_password_link').live('click', function()
    {
        var order = $(this).attr("order");
        var user = $(this).attr("user");
        var base = $(this).attr("base");
        $('#privileges_content[order="' + order + '"][base="' + base + '"]').hide(1000);
        $('#change_mysql_password_content[order="' + order + '"][base="' + base + '"]').hide(1000);
        if ( $('#change_mysql_password_content[order="' + order + '"][user="' + user + '"][base="' + base + '"]').is(':hidden') )
            $('#change_mysql_password_content[order="' + order + '"][user="' + user + '"][base="' + base + '"]').show(1000);
        return false;
    });
    $('a#add_database').live('click', function()
    {
        if  ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        var base = $('input[name="database_name"][order="' + order + '"]').val();

        if (!$('#database_form[order="' + order + '"]').valid())
            return false;
        if ( $('#base_item[order="' + order + '"][base="' + base + '"]').size() != 0)
        {
            alert('Уже создана база с таким именем!');
            return false;
        }
        $('#synch_database[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, base:base},
             url: "./shared_databases/create",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_create_db[order="' + order + '"]').show();
             },
             success: function(html)
             {
                $('#synch_database[order="' + order + '"]').removeClass('inactive');
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, base:base},
                     url: "./shared_databases/not_active",
                     cache: false,
                     success: function(html)
                     {
                        $('#database_list[order="' + order + '"]').append(html);
                        sort_databases(order);
                        $('#add_database_content[order="' + order + '"]').hide(1000);
                        $('#load_icon_create_db[order="' + order + '"]').hide();
                        $('#load_icon_wait_db[order="' + order + '"][base="' + base + '"]').html('Создание БД');
                        $('#load_icon_wait_db[order="' + order + '"][base="' + base + '"]').append(load_logo);
                        $('#load_icon_wait_db[order="' + order + '"][base="' + base + '"]').show();
                     }
                });
             }
        });
        return false;
    });
    $('a#drop_database').live('click', function()
    {
        if (!confirm('Вы уверены что хотите удалить?'))
            return false;
        if  ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        var base = $(this).attr("base");
        $('#synch_database[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, base:base},
             url: "./shared_databases/remove",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_drop_db[order="' + order + '"][base="' + base + '"]').show();
             },
             success: function(html)
             {
                $('#synch_database[order="' + order + '"]').removeClass('inactive');
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, base:base},
                     url: "./shared_databases/not_active",
                     cache: false,
                     success: function(html)
                     {
                        $('#base_item[order="' + order + '"][base="' + base + '"]').replaceWith(html);
                        $('#load_icon_drop_db[order="' + order + '"][base="' + base + '"]').hide();
                        $('#load_icon_wait_db[order="' + order + '"][base="' + base + '"]').html('Удаление БД');
                        $('#load_icon_wait_db[order="' + order + '"][base="' + base + '"]').append(load_logo);
                        $('#load_icon_wait_db[order="' + order + '"][base="' + base + '"]').show();
                     }
                });
             }
        });
        return false;
    });
    $('a#add_mysql_user').live('click', function()
    {
        if  ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        var base = $(this).attr("base");
        var user = $('input[name="user_mysql_login"][order="' + order + '"][base="' + base + '"]').val();
        var password = $('input[name="user_mysql_password"][order="' + order + '"][base="' + base + '"]').val();
        if (!$('#create_mysql_user_form[order="' + order + '"][base="' + base + '"]').valid())
            return false;
        if ( $('#user_item[order="' + order + '"][user="' + user + '"][base="' + base + '"]').size() != 0)
        {
            alert('Уже создан пользователь с таким именем!');
            return false;
        }
        $('#synch_database[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, base:base, user:user, password:password},
             url: "./shared_databases/create_user",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_create_user[order="' + order + '"][base="' + base + '"]').show();
             },
             success: function(html)
             {
                $('#synch_database[order="' + order + '"]').removeClass('inactive');
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, base:base, user:user},
                     url: "./shared_dbusers/not_active",
                     cache: false,
                     success: function(html)
                     {
                        $('#add_mysql_user_content[order="' + order + '"][base="' + base + '"]').hide(1000);
                        $('#users_list[order="' + order + '"][base="' + base + '"]').append(html);
                        sort_mysql_users(base, order);
                        $('#load_icon_create_user[order="' + order + '"][base="' + base + '"]').hide();
                        $('#load_icon_wait_user[order="' + order + '"][user="' + user + '"][base="' + base + '"]').html('Создание mysql пользователя');
                        $('#load_icon_wait_user[order="' + order + '"][user="' + user + '"][base="' + base + '"]').append(load_logo);
                     }
                });
             }
        });
        return false;
    });
    $('a#drop_mysql_user').live('click', function()
    {
        if (!confirm('Вы уверены что хотите удалить?'))
            return false;
        if  ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        var base = $(this).attr("base");
        var user = $(this).attr("user");
        $('#synch_database[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, base:base, user:user},
             url: "./shared_databases/remove_user",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_drop_user[order="' + order + '"][base="' + base + '"][user="' + user + '"]').show();
             },
             success: function(html)
             {
                $('#synch_database[order="' + order + '"]').removeClass('inactive');
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, base:base, user:user},
                     url: "./shared_dbusers/not_active",
                     cache: false,
                     success: function(html)
                     {
                        $('#user_item[order="' + order + '"][user="' + user + '"][base="' + base + '"]').replaceWith(html);
                        $('#load_icon_drop_user[order="' + order + '"][user="' + user + '"][base="' + base + '"]').hide();
                        $('#load_icon_wait_user[order="' + order + '"][user="' + user + '"][base="' + base + '"]').html('Удаление mysql пользователя');
                        $('#load_icon_wait_user[order="' + order + '"][user="' + user + '"][base="' + base + '"]').append(load_logo);
                     }
                });
             }
        });
        return false;
    });
    $('a#change_mysql_password').live('click', function()
    {
        if ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        var base = $(this).attr("base");
        var user = $(this).attr("user");
        if (!$('#change_mysql_user_form[order="' + order + '"][user="' + user + '"][base="' + base + '"]').valid())
            return false;
        var password = $('input[name="user_mysql_change_password"][order="' + order + '"][user="' + user + '"][base="' + base + '"]').val();

        $('#synch_database[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, base:base, user:user, password:password},
             url: "./shared_databases/change_user_password",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_change_password[order="' + order + '"][user="' + user + '"][base="' + base + '"]').show();
             },
             success: function(html)
             {
                $('#synch_database[order="' + order + '"]').removeClass('inactive');
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, base:base, user:user},
                     url: "./shared_dbusers/not_active",
                     cache: false,
                     success: function(html)
                     {
                        $('#user_item[order="' + order + '"][user="' + user + '"][base="' + base + '"]').replaceWith(html);
                        $('#load_icon_change_password[order="' + order + '"][user="' + user + '"][base="' + base + '"]').hide();
                        $('#load_icon_wait_user[order="' + order + '"][user="' + user + '"][base="' + base + '"]').html('Изменение пароля');
                        $('#load_icon_wait_user[order="' + order + '"][user="' + user + '"][base="' + base + '"]').append(load_logo);
                     }
                });
             }
        });
        return false;
    });
    $('a#change_mysql_rights').live('click', function()
    {
        if ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        var base = $(this).attr("base");
        var user = $(this).attr("user");
        var rights = $('input[name="priviledge"][order="' + order + '"][user="' + user + '"][base="' + base + '"]');
        var rights_str = '';
        $.each(rights, function(index, obj)
        {
            if ( $(obj).is(':checked') )
                rights_str += 'Y_';
            else
                rights_str += 'N_';
        }
        );
        rights_str = rights_str.substring(0, rights_str.length - 1)
        $('#synch_database[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, base:base, user:user, rights:rights_str},
             url: "./shared_databases/change_user_rights",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_change_rights[order="' + order + '"][user="' + user + '"][base="' + base + '"]').show();
             },
             success: function(html)
             {
                $('#synch_database[order="' + order + '"]').removeClass('inactive');
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, base:base, user:user},
                     url: "./shared_dbusers/not_active",
                     cache: false,
                     success: function(html)
                     {
                        $('#user_item[order="' + order + '"][user="' + user + '"][base="' + base + '"]').replaceWith(html);
                        $('#load_icon_change_rights[order="' + order + '"][user="' + user + '"][base="' + base + '"]').hide();
                        $('#load_icon_wait_user[order="' + order + '"][user="' + user + '"][base="' + base + '"]').html('Изменение прав');
                        $('#load_icon_wait_user[order="' + order + '"][user="' + user + '"][base="' + base + '"]').append(load_logo);
                     }
                });
             }
        });
        return false;
    });
    $('#select_all_rights').live('click', function()
    {
        var order = $(this).attr("order");
        var base = $(this).attr("base");
        var user = $(this).attr("user");
        $('input[name="priviledge"][order="' + order + '"][user="' + user + '"][base="' + base + '"]').attr("checked","checked");
        return false;
    });
    $('#select_no_rights').live('click', function()
    {
        var order = $(this).attr("order");
        var base = $(this).attr("base");
        var user = $(this).attr("user");
        $('input[name="priviledge"][order="' + order + '"][user="' + user + '"][base="' + base + '"]').attr("checked","");
        return false;
    });
    $('#synch_database').live('click', function()
    {
        if  ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания отправки другого запроса')
            return false; 
        }
        var order = $(this).attr("order");
        $('#add_mysql_user[order="' + order + '"]').addClass('inactive');
        $('#drop_mysql_user[order="' + order + '"]').addClass('inactive');
        $('#add_database[order="' + order + '"]').addClass('inactive');
        $('#remove_database[order="' + order + '"]').addClass('inactive');
        $('#change_mysql_password[order="' + order + '"]').addClass('inactive');
        $('#change_mysql_rights[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order},
             url: "./shared_databases/synch",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_synch_db[order="' + order + '"]').show();
             },
             success: function(html)
             {
                $('#add_mysql_user[order="' + order + '"]').removeClass('inactive');
                $('#drop_mysql_user[order="' + order + '"]').removeClass('inactive');
                $('#add_database[order="' + order + '"]').removeClass('inactive');
                $('#remove_database[order="' + order + '"]').removeClass('inactive');
                $('#change_mysql_password[order="' + order + '"]').removeClass('inactive');
                $('#change_mysql_rights[order="' + order + '"]').removeClass('inactive');
                if (html != 'true')
                {
                    $.ajax(
                    {
                         type: 'POST',
                         data: {order:order},
                         url: "./shared_databases/show",
                         cache: false,
                         beforeSend: function()
                         {
                            $('#content[order="' + order + '"]').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
                         },
                         success: function(content)
                         {
                            $('#content[order="' + order +'"]').html(content);
                            sort_databases(order);
                            obj = $('#load_icon_synch_error[order="' + order + '"]');
                            obj.html(html);
                            obj.append("<br><a href='' onclick='obj.hide(); return false;'>скрыть</a>");
                            obj.prepend(error_logo);
                         }
                    });   
                }
                else
                {
                    restoreSharedLinks(order);
                    $('#databases[order="' + order +'"] a').click();
                }
             }
        });
        return false;
    });
    $('a#generate_mysql_new_password').live('click', function()
    {
        var order = $(this).attr("order");
        var base = $(this).attr("base");
        $.ajax(
        {
             type: 'POST',
             url: "./shared_email/generate_password",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_generate_mysql_new_password[order="' + order + '"][base="' + base + '"]').show();
             },
             success: function(html)
             {
                $('input[name="user_mysql_password"][order="' + order + '"][base="' + base + '"]').val(html);
                $('#create_mysql_user_form[order="' + order + '"][base="' + base + '"]').valid();
                $('#load_icon_generate_mysql_new_password[order="' + order + '"][base="' + base + '"]').hide();   
             }
        });
        return false;
    });
    $('a#generate_mysql_change_password').live('click', function()
    {
        var order = $(this).attr("order");
        var base = $(this).attr("base");
        var user = $(this).attr("user");
        $.ajax(
        {
             type: 'POST',
             url: "./shared_email/generate_password",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_generate_mysql_change_password[order="' + order + '"][user="' + user + '"][base="' + base + '"]').show();
             },
             success: function(html)
             {
                $('input[name="user_mysql_change_password"][order="' + order + '"][user="' + user + '"][base="' + base + '"]').val(html);
                $('#change_mysql_user_form[order="' + order + '"][user="' + user + '"][base="' + base + '"]').valid();
                $('#load_icon_generate_mysql_change_password[order="' + order + '"][user="' + user + '"][base="' + base + '"]').hide();   
             }
        });
        return false;
    });
    
    $('a#add_email_link').live('click', function()
    {
        var order = $(this).attr("order");
        var domain = $(this).attr("domain");
        $('#add_email_content[order="' + order + '"]').hide(1000);
        if ( $('#add_email_content[order="' + order + '"][domain="' + domain + '"]').is(':hidden') )
            $('#add_email_content[order="' + order + '"][domain="' + domain + '"]').show(1000);
        return false;
    });
    $('a#change_email_password_link').live('click', function()
    {
        var order = $(this).attr("order");
        var email = $(this).attr("email");
        $('#change_email_password_content[order="' + order + '"][email="' + email + '"]').hide(1000);
        if ( $('#change_email_password_content[order="' + order + '"][email="' + email + '"]').is(':hidden') )
        {
            $('#change_email_password_content[order="' + order + '"][email="' + email + '"]').show(1000);
        }
        return false;
    });
    $('a#add_email').live('click', function()
    {
        if ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        var domain = $(this).attr("domain");
        if (!$('#email_form[order="' + order + '"][domain="' + domain + '"]').valid())
            return false;
        var user = $('input[name="email_user"][order="' + order + '"][domain="' + domain + '"]').val();
        var password = $('input[name="email_password"][order="' + order + '"][domain="' + domain + '"]').val();
        if ( $('#email_item[order="' + order + '"][email="' + user + "@" + domain + '"]').size() != 0)
        {
            alert('Уже создан ящик с таким именем!');
            return false;
        }
        $('#synch_email[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, domain:domain, user:user, password:password},
             url: "./shared_email/create",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_create_email[order="' + order + '"][domain="' + domain + '"]').show();
             },
             success: function(html)
             {
                $('#synch_email[order="' + order + '"]').removeClass('inactive'); 
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, email: user + "@" + domain},
                     url: "./shared_email/not_active",
                     cache: false,
                     success: function(html)
                     {
                         //alert(html);
                        $('#email_list[order="' + order + '"][domain="' + domain + '"]').append(html);
                        sort_items(order, domain);
                        $('#load_icon_create_email[order="' + order + '"][domain="' + domain + '"]').hide();
                        $('#add_email_content[order="' + order + '"][domain="' + domain + '"]').hide();                      
                        $('#load_icon_wait_email[order="' + order + '"][email="' + user + "@" + domain + '"]').html('Создание ящика');
                        $('#load_icon_wait_email[order="' + order + '"][email="' + user + "@" + domain + '"]').append(load_logo);
                        //if ($('#domain_list[order="' + order + '"][domain="' + domain + '"]').size() == 0)
                        //    $('#email').trigger('click');
                     }
                });
             }
        });
        return false;
    });
    $('a#drop_email').live('click', function()
    {
        if (!confirm('Вы уверены что хотите удалить?'))
            return false;
        if  ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        var email = $(this).attr("email");
        $('#synch_email[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, email:email},
             url: "./shared_email/remove",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_drop_email[order="' + order + '"][email="' + email + '"]').show();
             },
             success: function(html)
             {
                $('#synch_email[order="' + order + '"]').removeClass('inactive');
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, email:email},
                     url: "./shared_email/not_active",
                     cache: false,
                     success: function(html)
                     {                 
                        $('#email_item[order="' + order + '"][email="' + email + '"]').replaceWith(html);
                        $('#load_icon_drop_email[order="' + order + '"][email="' + email + '"]').hide();
                        $('#load_icon_wait_email[order="' + order + '"][email="' + email + '"]').html('Удаление ящика');
                        $('#load_icon_wait_email[order="' + order + '"][email="' + email + '"]').append(load_logo);
                     }
                });
             }
        });
        return false;
    });
    $('a#change_email').live('click', function()
    {
        if ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        var email = $(this).attr("email");

        if (!$('#change_email_password_form[order="' + order + '"][emails="' + email + '"]').valid())
            return false;
        var password = $('input[name="change_email_password"][order="' + order + '"][emails="' + email + '"]').val();

        $('#synch_email[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, email:email, password:password},
             url: "./shared_email/change",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_change_email[order="' + order + '"][email="' + email + '"]').show();
             },
             success: function(html)
             {
                $('#synch_email[order="' + order + '"]').removeClass('inactive'); 
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, email:email},
                     url: "./shared_email/not_active",
                     cache: false,
                     success: function(html)
                     {
                        $('#email_item[order="' + order + '"][email="' + email + '"]').replaceWith(html);
                        $('#load_icon_change_email[order="' + order + '"][email="' + email + '"]').hide();
                        $('#change_email_password_content[order="' + order + '"][email="' + email + '"]').hide();                      
                        $('#load_icon_wait_email[order="' + order + '"][email="' + email + '"]').html('Изменение пароля');
                        $('#load_icon_wait_email[order="' + order + '"][email="' + email + '"]').append(load_logo);
                     }
                });
             }
        });
        return false;
    });
    $('#synch_email').live('click', function()
    {
        if  ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания отправки другого запроса')
            return false; 
        }
        var order = $(this).attr("order");
        $('#add_email[order="' + order + '"]').addClass('inactive');
        $('#drop_email[order="' + order + '"]').addClass('inactive');
        $('#change_email[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order},
             url: "./shared_email/synch",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_synch_email[order="' + order + '"]').show();
             },
             success: function(html)
             {
                $('#add_email[order="' + order + '"]').removeClass('inactive');
                $('#drop_email[order="' + order + '"]').removeClass('inactive');
                $('#change_email[order="' + order + '"]').removeClass('inactive');
                if (html != 'true')
                {
                    $.ajax(
                    {
                         type: 'POST',
                         data: {order:order},
                         url: "./shared_email/show",
                         cache: false,
                         beforeSend: function()
                         {
                            $('#content[order="' + order + '"]').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
                         },
                         success: function(content)
                         {
                            $('#content[order="' + order +'"]').html(content);
                            var domains = $('#domain_list[order="' + order + '"] h2 span');
                            $.each(domains, function(index, obj)
                            {
                                sort_items(order, $(obj).html());
                            }
                            );
                            obj = $('#load_icon_synch_error[order="' + order + '"]');
                            obj.html(html);
                            obj.append("<br><a href='' onclick='obj.hide(); return false;'>скрыть</a>");
                            obj.prepend(error_logo);
                         }
                    });   
                }
                else
                {
                    restoreSharedLinks(order);
                    $('#email[order="' + order +'"] a').trigger('click');
                }
             }
        });
        return false;
    });
    $('a#generate_email_password').live('click', function()
    {
        var order = $(this).attr("order");
        var email = $(this).attr("email");
        var domain = $(this).attr("domain");
        $.ajax(
        {
             type: 'POST',
             url: "./shared_email/generate_password",
             cache: false,
             beforeSend: function()
             {
                if (email)
                    $('#load_icon_generate_email_password[order="' + order + '"][email="' + email + '"]').show();
                else
                    $('#load_icon_generate_email_password[order="' + order + '"][domain="' + domain + '"]').show();
             },
             success: function(html)
             {
                if (email)
                {
                    $('input[name="change_email_password"][order="' + order + '"][emails="' + email + '"]').val(html);
                    $('#change_email_password_form[order="' + order + '"][emails="' + email + '"]').valid();
                    $('#load_icon_generate_email_password[order="' + order + '"][email="' + email + '"]').hide(); 
                }
                else
                {
                    $('input[name="email_password"][order="' + order + '"][domain="' + domain + '"]').val(html);
                    $('input[name="email_password"][order="' + order + '"][domain="' + domain + '"]').valid();
                    $('#load_icon_generate_email_password[order="' + order + '"][domain="' + domain + '"]').hide();
                }    
             }
        });
        return false;
    });
    
    $('a#add_ftp_link').live('click', function()
    {
        var order = $(this).attr("order");
        $('#add_ftp_content[order="' + order + '"]').hide(1000);
        if ( $('#add_ftp_content[order="' + order + '"]').is(':hidden') )
            $('#add_ftp_content[order="' + order + '"]').show(1000);
        return false;
    });
    $('a#change_ftp_password_link').live('click', function()
    {
        var order = $(this).attr("order");
        var user = $(this).attr("user");
        $('#change_ftp_password_content[order="' + order + '"][user="' + user + '"]').hide(1000);
        if ( $('#change_ftp_password_content[order="' + order + '"][user="' + user + '"]').is(':hidden') )
        {
            $('#change_ftp_password_content[order="' + order + '"][user="' + user + '"]').show(1000);
        }
        return false;
    });
    $('a#add_ftp').live('click', function()
    {
        if ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        if (!$('#ftp_form[order="' + order + '"]').valid())
            return false;
        var user = $('input[name="ftp_user_name"][order="' + order + '"]').val();
        var password = $('input[name="ftp_new_password"][order="' + order + '"]').val();
        //password = toUnicode(password);
        var dir = $('input[name="ftp_directory"][order="' + order + '"]').val();
        //dir = escape(encodeURIComponent(dir));
        if ( $('#ftp_item[order="' + order + '"][user="' + user + '"]').size() != 0)
        {
            alert('Уже создан пользователь с таким именем!');
            return false;
        }
        $('#synch_ftp[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, user:user, password:password, dir:dir},
             url: "./shared_ftp/create",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_create_ftp[order="' + order + '"]').show();
             },
             success: function(html)
             {
                $('#synch_ftp[order="' + order + '"]').removeClass('inactive'); 
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, user:user},
                     url: "./shared_ftp/not_active",
                     cache: false,
                     success: function(html)
                     {
                        $('#ftp_list[order="' + order + '"]').append(html);
                        sort_ftp_users(order);
                        $('#load_icon_create_ftp[order="' + order + '"]').hide();
                        $('#add_ftp_content[order="' + order + '"]').hide();                      
                        $('#load_icon_wait_ftp[order="' + order + '"][user="' + user + '"]').html('Создание пользователя');
                        $('#load_icon_wait_ftp[order="' + order + '"][user="' + user + '"]').append(load_logo);
                     }
                });
             }
        });
        return false;
    });
    $('a#drop_ftp').live('click', function()
    {
        if (!confirm('Вы уверены что хотите удалить?'))
            return false;
        if  ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        var user = $(this).attr("user");
        $('#synch_ftp[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, user:user},
             url: "./shared_ftp/remove",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_drop_ftp[order="' + order + '"][user="' + user + '"]').show();
             },
             success: function(html)
             {
                $('#synch_ftp[order="' + order + '"]').removeClass('inactive');
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, user:user},
                     url: "./shared_ftp/not_active",
                     cache: false,
                     success: function(html)
                     {             
                        $('#ftp_item[order="' + order + '"][user="' + user + '"]').replaceWith(html);
                        $('#load_icon_drop_ftp[order="' + order + '"][user="' + user + '"]').hide();
                        $('#load_icon_wait_ftp[order="' + order + '"][user="' + user + '"]').html('Удаление пользователя');
                        $('#load_icon_wait_ftp[order="' + order + '"][user="' + user + '"]').append(load_logo);
                     }
                });
             }
        });
        return false;
    });
    $('a#change_ftp').live('click', function()
    {
        if ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        var user = $(this).attr("user");
        if (!$('#change_ftp_password_form[order="' + order + '"][user="' + user + '"]').valid())
            return false;
        var password = $('input[name="ftp_change_password"][order="' + order + '"][user="' + user + '"]').val();
        $('#synch_ftp[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, user:user, password:password},
             url: "./shared_ftp/change",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_change_ftp[order="' + order + '"][user="' + user + '"]').show();
             },
             success: function(html)
             {
                $('#synch_ftp[order="' + order + '"]').removeClass('inactive'); 
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, user:user},
                     url: "./shared_ftp/not_active",
                     cache: false,
                     success: function(html)
                     {
                        $('#ftp_item[order="' + order + '"][user="' + user + '"]').replaceWith(html);
                        $('#load_icon_change_ftp[order="' + order + '"][user="' + user + '"]').hide();
                        $('#change_ftp_password_content[order="' + order + '"][user="' + user + '"]').hide();                      
                        $('#load_icon_wait_ftp[order="' + order + '"][user="' + user + '"]').html('Изменение пароля');
                        $('#load_icon_wait_ftp[order="' + order + '"][user="' + user + '"]').append(load_logo);
                     }
                });
             }
        });
        return false;
    });
    $('#synch_ftp').live('click', function()
    {
        if  ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания отправки другого запроса')
            return false; 
        }
        var order = $(this).attr("order");
        $('#add_ftp[order="' + order + '"]').addClass('inactive');
        $('#drop_ftp[order="' + order + '"]').addClass('inactive');
        $('#change_ftp[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order},
             url: "./shared_ftp/synch",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_synch_ftp[order="' + order + '"]').show();
             },
             success: function(html)
             {
                $('#add_ftp[order="' + order + '"]').removeClass('inactive');
                $('#drop_ftp[order="' + order + '"]').removeClass('inactive');
                $('#change_ftp[order="' + order + '"]').removeClass('inactive');
                if (html != 'true')
                {
                    $.ajax(
                    {
                         type: 'POST',
                         data: {order:order},
                         url: "./shared_ftp/show",
                         cache: false,
                         beforeSend: function()
                         {
                            $('#content[order="' + order + '"]').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
                         },
                         success: function(content)
                         {
                            $('#content[order="' + order +'"]').html(content);
                            sort_ftp_users(order);
                            obj = $('#load_icon_synch_error[order="' + order + '"]');
                            obj.html(html);
                            obj.append("<br><a href='' onclick='obj.hide(); return false;'>скрыть</a>");
                            obj.prepend(error_logo);
                         }
                    });   
                }
                else
                {
                    restoreSharedLinks(order);
                    $('#ftp[order="' + order +'"] a').trigger('click');
                }
             }
        });
        return false;
    });
    $('a#generate_ftp_password').live('click', function()
    {
        var order = $(this).attr("order");
        var user = $(this).attr("user");

        $.ajax(
        {
             type: 'POST',
             url: "./shared_email/generate_password",
             cache: false,
             beforeSend: function()
             {
                if (user)
                    $('#load_icon_generate_ftp_password[order="' + order + '"][user="' + user + '"]').show();
                else
                    $('#load_icon_generate_ftp_new_password[order="' + order + '"]').show();
             },
             success: function(html)
             {
                if (user)
                {
                    $('input[name="ftp_change_password"][order="' + order + '"][user="' + user + '"]').val(html);
                    $('input[name="ftp_change_password"][order="' + order + '"][user="' + user + '"]').valid();
                    $('#load_icon_generate_ftp_password[order="' + order + '"][user="' + user + '"]').hide(); 
                }
                else
                {
                    $('input[name="ftp_new_password"][order="' + order + '"]').val(html);
                    $('input[name="ftp_new_password"][order="' + order + '"]').valid();
                    $('#load_icon_generate_ftp_new_password[order="' + order + '"]').hide();
                }
             }
        });
        return false;
    });
    
    $('select[name="dns_type"]').live('change', function()
    {
        var order = $(this).attr("order");
        var domain = $(this).attr("domain");
        var select = $(this).val();
        if ((select == 2) || (select == 6))
        {
            if (!$('input[name="dns_name"][order="' + order + '"][domain="' + domain + '"]').val())
                $('input[name="dns_name"][order="' + order + '"][domain="' + domain + '"]').val(domain + ".");
        }
        else if (select == 4)
        {
            if (!$('input[name="dns_value"][order="' + order + '"][domain="' + domain + '"]').val())
                $('input[name="dns_value"][order="' + order + '"][domain="' + domain + '"]').val(domain + ".");
        }
        return false;
    });
    $('a#change_dns_link').live('click', function()
    {
        var order = $(this).attr("order");
        var hashs = $(this).attr("hashs");
        //alert(order);
        //alert(hashs);
        var name_obj = $('#dns_name[order="' + order + '"][hashs="' + hashs + '"]');
        var type_obj = $('#dns_type[order="' + order + '"][hashs="' + hashs + '"]');
        var value_obj = $('#dns_value[order="' + order + '"][hashs="' + hashs + '"]');
        if ( !$('input[name="dns_change_name"][order="' + order + '"][hashs="' + hashs + '"]').is(':visible') )
        {
            name_obj.html('<input type="text" name="dns_change_name" order="' + order + '" hashs="' + hashs + '" size="6" value="' + name_obj.html() + '"></input>');
            
            var type = type_obj.html();
            type_obj.html('<select name="dns_change_type" order="' + order + '" hashs="' + hashs + '">');
            $('select[name="dns_change_type"][order="' + order + '"][hashs="' + hashs + '"]').html($('select[name="dns_type"]').html());
            type_obj.append('</select>');
            //$('select[name="dns_change_type"][order="' + order + '"][hashs="' + hashs + '"] option:selected').val('NS');
            
            value_obj.html('<input type="text" name="dns_change_value" order="' + order + '" hashs="' + hashs + '" size="6" value="' + value_obj.html() + '"></input>');
            $('#change_dns_content[order="' + order + '"][hashs="' + hashs + '"]').show();
            restore_change_dns_validation(order, hashs);
        }
        else
        {
            $.ajax(
            {
                 type: 'POST',
                 data: {order:order, hash:hashs},
                 url: "./shared_dns/active",
                 cache: false,
                 beforeSend: function()
                 {
                    $('#load_icon_dns[order="' + order + '"][hashs="' + hashs + '"]').show();
                 },
                 success: function(html)
                 {
                    $('#load_icon_dns[order="' + order + '"][hashs="' + hashs + '"]').hide();                   
                    $('$dns_item[order="' + order + '"][hashs="' + hashs + '"]').remove();
                    $('#dns_list[order="' + order + '"]').append(html);
                    sort_dns(order);
                 }
            });
            //$('#change_dns_content[order="' + order + '"][hash="' + hashs + '"]').hide();
        }
        return false;
    });
    $('a#add_dns').live('click', function()
    {
        if ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        var domain = $(this).attr("domain");
        if (!$('#dns_add_form[order="' + order + '"]').valid())
            return false;
        var name = $('input[name="dns_name"][order="' + order + '"][domain="' + domain + '"]').val();
        var type = $('select[name="dns_type"][order="' + order + '"][domain="' + domain + '"] :selected').text();
        var value = $('input[name="dns_value"][order="' + order + '"][domain="' + domain + '"]').val();
        var hashs = MD5(name + type + value + domain);

        if ( $('#dns_item[hashs="' + hashs + '"]').size() != 0)
        {
            alert('Уже создана такая запись!');
            return false;
        }
        $('#synch_dns[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, domain:domain, name:name, type:type, value:value},
             url: "./shared_dns/create",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_create_dns[order="' + order + '"][domain="' + domain + '"]').show();
             },
             success: function(html)
             {
                $('#synch_dns[order="' + order + '"]').removeClass('inactive');
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, hash:hashs},
                     url: "./shared_dns/not_active",
                     cache: false,
                     success: function(html)
                     {
                        $('#dns_list[order="' + order + '"]').append(html);
                        sort_dns(order);
                        $('#load_icon_create_dns[order="' + order + '"][domain="' + domain + '"]').hide();                    
                        $('#load_icon_wait_dns[hashs="' + hashs + '"]').html('Создание записи');
                        $('#load_icon_wait_dns[hashs="' + hashs + '"]').append(load_logo);
                     }
                });
             }
        });
        return false;
    });
    $('a#drop_dns').live('click', function()
    {
        if ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        var hashs = $(this).attr("hashs");
        
        $('#synch_dns[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, hash:hashs},
             url: "./shared_dns/remove",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_dns[order="' + order + '"][hashs="' + hashs + '"]').show();
             },
             success: function(html)
             {
                $('#synch_dns[order="' + order + '"]').removeClass('inactive');
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, hash:hashs},
                     url: "./shared_dns/not_active",
                     cache: false,
                     success: function(html)
                     {
                        $('$dns_item[order="' + order + '"][hashs="' + hashs + '"]').remove();
                        $('#dns_list[order="' + order + '"]').append(html);
                        sort_dns(order);
                        $('#load_icon_dns[order="' + order + '"][hashs="' + hashs + '"]').hide();                    
                        $('#load_icon_wait_dns[hashs="' + hashs + '"]').html('Удаление записи');
                        $('#load_icon_wait_dns[hashs="' + hashs + '"]').append(load_logo);
                     }
                });
             }
        });
        return false;
    });
    $('a#change_dns').live('click', function()
    {
        if ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания синхронизации')
            return false; 
        }
        var order = $(this).attr("order");
        var hashs = $(this).attr("hashs");
        if (!$('#dns_change_form[order="' + order + '"][hashs="' + hashs + '"]').valid())
            return false;
        var name = $('input[name="dns_change_name"][order="' + order + '"][hashs="' + hashs + '"]').val();
        var type = $('select[name="dns_change_type"][order="' + order + '"][hashs="' + hashs + '"] option:selected').text();
        var value = $('input[name="dns_change_value"][order="' + order + '"][hashs="' + hashs + '"]').val();
        $('#synch_dns[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, hash:hashs, name:name, type:type, value:value},
             url: "./shared_dns/change",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_dns[order="' + order + '"][hashs="' + hashs + '"]').show();
             },
             success: function(html)
             {
                $('#synch_dns[order="' + order + '"]').removeClass('inactive');
                $.ajax(
                {
                     type: 'POST',
                     data: {order:order, hash:hashs},
                     url: "./shared_dns/not_active",
                     cache: false,
                     success: function(html)
                     {
                        $('$dns_item[order="' + order + '"][hashs="' + hashs + '"]').remove();
                        $('#dns_list[order="' + order + '"]').append(html);
                        sort_dns(order);                   
                        $('#load_icon_dns[order="' + order + '"][hashs="' + hashs + '"]').hide();
                        $('#load_icon_wait_dns[hash="' + hashs + '"]').html('Изменение записи');
                        $('#load_icon_wait_dns[hash="' + hashs + '"]').append(load_logo);
                     }
                });
             }
        });
        return false;
    });
    $('#synch_dns').live('click', function()
    {
        if  ($(this).hasClass('inactive')) 
        {
            alert('Дождитесь окончания отправки другого запроса')
            return false; 
        }
        var order = $(this).attr("order");
        var domain = $(this).attr("domain");
        $('#add_dns[order="' + order + '"]').addClass('inactive');
        $('#drop_dns[order="' + order + '"]').addClass('inactive');
        $('#change_dns[order="' + order + '"]').addClass('inactive');
        $.ajax(
        {
             type: 'POST',
             data: {order:order, domain:domain},
             url: "./shared_dns/synch",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_synch_dns[order="' + order + '"]').show();
             },
             success: function(html)
             {
                $('#add_dns[order="' + order + '"]').removeClass('inactive');
                $('#drop_dns[order="' + order + '"]').removeClass('inactive');
                $('#change_dns[order="' + order + '"]').removeClass('inactive');
                if (html != 'true')
                {
                    $.ajax(
                    {
                         type: 'POST',
                         data: {order:order, domain:domain},
                         url: "./shared_dns/show",
                         cache: false,
                         beforeSend: function()
                         {
                            $('#content[order="' + order + '"]').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
                         },
                         success: function(content)
                         {
                            $('#content[order="' + order +'"]').html(content);
                            sort_dns(order);
                            obj = $('#load_icon_synch_error[order="' + order + '"]');
                            obj.html(html);
                            obj.append("<br><a href='' onclick='obj.hide(); return false;'>скрыть</a>");
                            obj.prepend(error_logo);
                         }
                    }); 
                }
                else
                {
                    $.ajax(
                    {
                         type: 'POST',
                         data: {order:order, domain:domain},
                         url: "./shared_dns/show",
                         cache: false,
                         beforeSend: function()
                         {
                            $('#content[order="' + order + '"]').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
                         },
                         success: function(html)
                         {
                            restoreSharedLinks(order);
                            $('#content[order="' + order +'"]').html(html);
                            sort_dns(order);
                         }
                    });
                }
             }
        });
        return false;
    });

    $('#change_tarif').live('click', function()
    {
        var order = $(this).attr("order");
        var select = $('select[name="tarif"][order="' + order + '"]').val()
        $.ajax(
        {
             type: 'POST',
             data: {order:order, hash:select},
             url: "./shared_tarif/change",
             cache: false,
             success: function(html)
             {
                $('#summary[order="' + order +'"]').click();
             }
        });
        return false;
    });
    
    $('input[name="change_email_password"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    $('input[name="email_user"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    $('input[name="email_password"]').live('click', function()
    {
        $(this).valid();
        return false;
    });

    $('input[name="database_name"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    $('input[name="user_mysql_login"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    $('input[name="user_mysql_password"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    $('input[name="user_mysql_change_password"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    $('input[name="priviledge"]').live('change', function()
    {
        var order = $(this).attr("order");
        var base = $(this).attr("base");
        var user = $(this).attr("user");
        $('#privileges_content[order="' + order + '"][user="' + user + '"][base="' + base + '"] #change_status').show();
        return false;
    });
    $('input[name="ftp_user_name"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    $('input[name="ftp_new_password"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    $('input[name="ftp_directory"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    $('input[name="ftp_change_password"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    $('input[name="dns_name"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    $('input[name="dns_value"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    $('input[name="dns_change_name"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    $('input[name="dns_change_value"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    $('input[name="ip_count"]').live('click', function()
    {
        $(this).valid();
        return false;
    });
    
    $('#remove_order').live('click', function()
    {
        var order = $(this).attr("order");
        $.ajax(
        {
             type: 'POST',
             data: {order:order},
             url: "./shared_remove",
             cache: false,
             success: function(html)
             {
                window.location.href = 'shared_show';
             }
        });
        return false;
    });
    $('#extension_order').live('click', function()
    {
        var order = $(this).attr("order");
        $.ajax(
        {
             type: 'POST',
             data: {order:order},
             url: "./shared_extension",
             cache: false,
             beforeSend: function()
             {
                $('#content[order="' + order + '"]').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
             },
             success: function(html)
             {
                 $('#content[order="' + order +'"]').html(html);
             }
        });
        return false;
    });
    $('#change_tarif_link').live('click', function()
    {
        var order_id = $(this).attr("order");
        $('div[id="change_tarif_content"]').hide(1000);
        if ( $('#change_tarif_content[order="' + order_id + '"]').is(':hidden') )
            $('#change_tarif_content[order="' + order_id + '"]').show(1000);
        return false;
    });
    $('#change_tarif').live('click', function()
    {
        var order = $(this).attr("order");
        var select = $('select[name="tarif"][order="' + order + '"]').val()
        $.ajax(
        {
             type: 'POST',
             data: {order:order, hash:select},
             url: "./shared_tarif/change",
             cache: false,
             success: function(html)
             {
                $('#summary[order="' + order +'"]').click();
             }
        });
        return false;
    });
    
    $('#add_domain_to_order').live('click', function()
    {
        var order = $(this).attr("order");
        $.ajax(
        {
             url: "./domains_add_to_order",
             beforeSend: function()
             {
                $('#content[order="' + order + '"]').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
             },
             cache: false,
             success: function(html)
             {
                restoreSharedLinks(order);
                $('#content[order="' + order + '"]').html(html);
             }
        });
        return false;
    });
    $('#ip').live('click', function()
    {
        var order = $(this).attr("order");
        $.ajax(
        {
             type: 'POST',
             data: {order:order},
             url: "./shared_ips/show",
             cache: false,
             beforeSend: function()
             {
                $('#content[order="' + order + '"]').html('получение контента <img alt="загрузка" src="' + dir + '/i/load.gif">');
             },
             success: function(html)
             {
                restoreSharedLinks(order);
                $('#content[order="' + order +'"]').html(html);
             }
        });
        return false;
    });
    $('a#add_ip_to_order_link').live('click', function()
    {
        var order = $(this).attr("order");
        $('#add_ip_to_order_content[order="' + order + '"]').hide(1000);
        if ( $('#add_ip_to_order_content[order="' + order + '"]').is(':hidden') )
            $('#add_ip_to_order_content[order="' + order + '"]').show(1000);
        return false;
    });
    $('#add_ip_to_order').live('click', function()
    {
        var order = $(this).attr("order");
        if (!$('#add_ip_form[order="' + order + '"]').valid())
            return false;
        var count = $('input[name="ip_count"][order="' + order + '"]').val();
        $.ajax(
        {
             type: 'POST',
             data: {order:order, count:count},
             url: "./shared_ips/create",
             cache: false,
             beforeSend: function()
             {
                $('#load_icon_create_ip[order="' + order + '"]').show();
             },
             success: function(html)
             {
                $('#load_icon_create_ip[order="' + order + '"]').hide();
                if (html == "true")
                    $('#users_bills_tab').trigger('click');
             }
        });
        return false;
    });
});
